package com.hl.web;

import com.hl.service.ChangephoneService;
import com.hl.util.GeneralResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/change")
public class Changephone {
    @Autowired
    private ChangephoneService changephoneService;

    @RequestMapping("/changephone")
    public GeneralResult changephone(@RequestBody Map<String,String> requestBody) throws Exception {
        String phone = requestBody.get("phone");
        Integer userId = Integer.parseInt(requestBody.get("userId"));
        System.out.println(phone);
        System.out.println(userId);

        if (phone.length() == 11){
            changephoneService.updatePhone(phone,userId);
            return GeneralResult.success("修改成功");
        } else {
           return GeneralResult.fail();
        }


    }
}
